#
include "flow.util";#
include "flow.util.validate";


//基础数据
var domainid = getDomainid(); //域id
var lastmodified = getCurDate("yyyy-MM-dd HH:mm:ss"); //当前时间
var forname = 'cpmis/电子需求单/clause_present';
var author = getWebUser().getId(); //当前用户id
var author_depts = getWebUser().getDepartments();
var author_dept_index = author_depts.iterator().next().getId();
var formid = '11e8-3eec-f270c27d-8322-274e86807188';
var applicationid = getApplication();
var auditornames = getWebUser().getName(); //当前用户name

//得到选中记录的id
var message = "";
var selectId = getParameter("_selects");
var selectarr = splitText(selectId, ";");


var validateResult = batchUpdateClause(selectId, getItemValueAsString("sjbb"));
message = validateResult.message;
if (validateResult.result && !isNotNull(message)) {
    var tcbm = getItemValueAsString("tcbm"); //1. 提出部门
    var ms = getItemValueAsString("ms"); //2. 描述
    var xqbm_fzr = getItemValueAsString("xqbm_fzr_1"); //3. 需求部门负责人
    var sjbm_fzr = getItemValueAsString("sjbm_fzr_1"); //4. 设计部门负责人
    var kfgs_fzr = getItemValueAsString("kfgs_fzr_1"); //5. 开发公司负责人
    var jpcd = getItemValueAsString("jpcd"); //6. 紧迫程度
    var qwsxrq = getItemValueAsString("qwsxrq"); //7. 期望上线日期
    var xqtcyy = getItemValueAsString("xqtcyy"); //8. 需求提出原因
    var jhpgwcrq = getItemValueAsString("jhpgwcrq"); //9. 计划评估完成日期
    var xqlx = getItemValueAsString("xqlx"); //10. 需求类型
    var sxpt = getItemValueAsString("sxpt"); //11. 实现平台
    var sxxt = getItemValueAsString("sxxt_1"); //12. 实现系统
    var sxzxt = getItemValueAsString("sxzxt_1"); //13. 实现子系统
    var sxsl = getItemValueAsString("sxsl"); //实现实例
    var sxmk = getItemValueAsString("sxmk"); //14. 实现模块
    var yyghbz = getItemValueAsString("yyghbz"); //17. 应用规划备注
    var sjbb = getItemValueAsString("sjbb"); //18. 计划版本
    var xtjgyxfx = getItemValueAsString("xtjgyxfx"); //19. 系统架构影响分析

    for (var i = 0; i < selectarr.length; i++) { //循环遍历已勾选的条目
        var docid = selectarr[i];
        var id = countNext2('', true, true, true, 6);
        var sql_old = "select * from tlk_clause_present where id = '" + selectarr[i] + "'";
        var datas = findBySQL(sql_old);
        var lastmodifier = datas.getLastmodifier(); //获取最后操作人
        var lastmodified_old = datas.getLastmodified(); //获取最后操作时间

        var columnName = ["tmbh", "zt", "tcbm", "xmztc", "sywh", "ms", "wzfa", "xqbg", "jpcd", "qwsxsj", "tcyy", "xqbmfzr", "jhpgwcsj", "xqlx", "sxpt", "xqsxxt", "xqzxt", "xqsxsl", "xqsxmk", "zh_trl", "wb_trl", "trl", "htl", "yyghbz", "sjbmfzr", "xtjgyxfx", "jhsxbb", "dqbb", "qbbb", "gskffzr", "tag1", "tag2", "tag3"];
        var columnValue = new Array();
        for (var t = 0; t < columnName.length; t++) {
            columnValue[t] = datas.getItemValueAsString(columnName[t]);
        }
        var sql_into_log = "INSERT INTO cpmis.log_clause_present (" +
            "id," + //log表id
            "lastmodified," + //最后操作时间
            "formname," + //表名
            "author," + //作者
            "author_dept_index," +
            "created," + //创建时间
            "formid," + //表id
            "istmp," +
            "versions," + //文档版本
            "applicationid," +
            "stateint," +
            "lastmodifier," + //最后操作人
            "domainid," + //域id
            "auditorlist," + //审批人列表
            "doc_id"; //对应的tlk表id
        for (var k = 0; k < columnName.length; k++) {
            sql_into_log = sql_into_log + ",item_" + columnName[k] + "";
        }
        sql_into_log = sql_into_log + ") VALUES (" +
            "'" + id + "'," + //log表id
            "'" + lastmodified_old + "'," + //最后操作时间
            "'" + forname + "'," + //表名
            "'" + author + "'," + //作者
            "'" + author_dept_index + "'," +
            "'" + lastmodified_old + "'," + //创建时间
            "'" + formid + "'," + //表id
            "0," +
            "'1'," + //文档版本
            "'" + applicationid + "'," +
            "0," +
            "'" + lastmodifier + "'," + //最后操作人
            "'" + domainid + "'," + //域id
            "'{}'," + //审批人列表
            "'" + docid + "'"; //对应的tlk表id
        for (var n = 0; n < columnValue.length; n++) {
            var val = columnValue[n];
            if ("qwsxsj".equals(columnName[n]) || "jhpgwcsj".equals(columnName[n])) {
                if (!isNotNull(val)) {
                    sql_into_log = sql_into_log + "," + val + "";
                } else {
                    sql_into_log = sql_into_log + ",'" + val + "'";
                }
            } else {
                sql_into_log = sql_into_log + ",'" + val + "'";
            }
        }
        sql_into_log = sql_into_log + ")";
        println("【批量修改】记录日志：" + sql_into_log);
        insertByDSName("cpmis", sql_into_log);




        /**
         - - - - -               - - - - 
         - - - - - UPDATE CLAUSE - - - - 
         - - - - -  更新条目信息  - - - -  
         - - - - -               - - - -  
        */
        if ((isNotNull(sxpt) && isNotNull(sxxt)) || (!isNotNull(sxpt) && !isNotNull(sxxt))) {
            var sql = "update tlk_clause_present set item_tmbh = item_tmbh ";
            var paramsKey = createObject("java.util.ArrayList");
            var paramsVal = createObject("java.util.ArrayList");
            if (isNotNull(tcbm)) { //提出部门
                paramsKey.add("item_tcbm");
                paramsVal.add(tcbm)
            }
            if (isNotNull(ms)) { //描述
                paramsKey.add("item_ms");
                paramsVal.add(ms)
            }
            if (isNotNull(xqbm_fzr)) { //需求部门负责人
                paramsKey.add("item_xqbmfzr");
                paramsVal.add(xqbm_fzr)
            }
            if (isNotNull(sjbm_fzr)) { //设计部门负责人
                paramsKey.add("item_sjbmfzr");
                paramsVal.add(sjbm_fzr)
            }
            if (isNotNull(kfgs_fzr)) { //开发公司负责人
                paramsKey.add("item_gskffzr");
                paramsVal.add(kfgs_fzr)
            }
            if (isNotNull(jpcd)) { //紧迫程度
                paramsKey.add("item_jpcd");
                paramsVal.add(jpcd)
            }
            if (isNotNull(qwsxrq)) { //期望上线时间
                paramsKey.add("item_qwsxsj");
                paramsVal.add(qwsxrq)
            }
            if (isNotNull(xqtcyy)) { //需求提出原因
                paramsKey.add("item_tcyy");
                paramsVal.add(xqtcyy)
            }
            if (isNotNull(jhpgwcrq)) { //计划评估完成时间
                paramsKey.add("item_jhpgwcsj");
                paramsVal.add(jhpgwcrq)
            }
            if (isNotNull(xqlx)) { //需求类型
                paramsKey.add("item_xqlx");
                paramsVal.add(xqlx)
            }
            if (isNotNull(sxpt) || isNotNull(sxxt)) { //现在是通过试图选择实现，一旦系统有值，则五个数据均是最新的，因此都要更新
                paramsKey.add("item_sxpt");
                paramsVal.add(sxpt);
                paramsKey.add("item_xqsxxt"); //系统
                paramsVal.add(sxxt);
                paramsKey.add("item_xqzxt"); //子系统
                paramsVal.add(sxzxt.replace("--", ""))
                paramsKey.add("item_xqsxmk"); //实现模块
                paramsVal.add(sxmk.replace("--", ""))
                paramsKey.add("item_xqsxsl"); //实现实例
                paramsVal.add(sxsl);
            }
            if (isNotNull(yyghbz)) { //应用规划备注
                paramsKey.add("item_yyghbz");
                paramsVal.add(yyghbz)
            }
            if (isNotNull(sxsl)) {
                paramsKey.add("item_xqsxsl");
                paramsVal.add(sxsl);
            }
            if (isNotNull(xtjgyxfx)) { //系统架构影响分析
                paramsKey.add("item_xtjgyxfx");
                paramsVal.add(xtjgyxfx)
            }
            if (isNotNull(sjbb)) { //计划版本与当前版本同步更新
                paramsKey.add("item_jhsxbb");
                paramsVal.add(sjbb)
                paramsKey.add("item_dqbb");
                paramsVal.add(sjbb)
            }
            if (null != paramsKey && null != paramsVal && paramsKey.size() > 0 && paramsKey.size() == paramsVal.size()) {
                for (var n = 0; n < paramsKey.size(); n++) {
                    sql = sql + ", " + paramsKey.get(n) + "='" + paramsVal.get(n) + "'";
                }
                sql = sql + " where id = '" + docid + "'";
            }
            println("【批量修改】批量修改：" + sql);
            updateByDSName(datasource, sql);
        } else {
            message = "实现平台和实现系统必须同时修改";
        }
    }
}

message;